#include "swap.c"
#include "array_and_file.c"
#pragma once

void selection_sort (int *array, int file_size, char *unsorted_input_file, char *sorted_output_file)
{
    int i, j, min, temp, index_of_min;

	read_file_into_array (array, file_size, unsorted_input_file);

    for (i = 0; i < file_size; i++) {
        min = array[i];
        index_of_min = i;		//This line is important. Its absence will cause trouble if array[i] itself is the smallest element.
        for (j = i + 1; j < file_size; j++) {
            if (array[j] < min) {
                min = array[j];
                index_of_min = j;
            }
        }
    swap (&array[i], &array[index_of_min]);
    }

	write_array_to_file (array, file_size, sorted_output_file);
}
